package topcoder.srm217;

import java.util.Arrays;

public class PlayGame {
	public int saveCreatures(int[] you, int[] computer) {
		int res = 0;
		int n = you.length;

		Arrays.sort(you);
		Arrays.sort(computer);

		for (int i = n - 1; i >= 0; i--) {
			int max = -1;

			for (int j = i; j >= 0; j--) {
				if (computer[j] < you[i]) {
					max = j;
					break;
				}
			}

			// System.out.println("id = " + i + " j = " + max);
			if (max != -1) {
				res += you[i];
				computer[max] = Integer.MAX_VALUE;
			}
		}

		return res;

	}

	public static void main(String[] args) {
		PlayGame pg = new PlayGame();
		int[] you = { 651, 321, 106, 503, 227, 290, 915, 549, 660, 115, 491,
				378, 495, 789, 507, 381, 685, 530, 603, 394, 7, 704, 101, 620,
				859, 490, 744, 495, 379, 781, 550, 356, 950, 628, 177, 373,
				132, 740, 946, 609, 29, 329, 57, 636, 132, 843, 860, 594, 718,
				849 };
		int[] comp = { 16, 127, 704, 614, 218, 67, 169, 621, 340, 319, 366,
				658, 798, 803, 524, 608, 794, 896, 145, 627, 401, 253, 137,
				851, 67, 426, 571, 302, 546, 225, 311, 111, 804, 135, 284, 784,
				890, 786, 740, 612, 360, 852, 228, 859, 229, 249, 540, 979, 55,
				82 };

		;

		System.out.println(pg.saveCreatures(you, comp));
	}

}
